package org.example.cloudprviderpayment8001.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import org.aspectj.lang.reflect.MethodSignature;
import org.example.cloudprviderpayment8001.annotion.TimeoutBack;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Order(0)
public class TimeoutBackAspect {
    @Pointcut("@annotation(org.example.cloudprviderpayment8001.annotion.TimeoutBack)")
    public void pointcut(){};

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
        System.out.println("timout方法");
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Method method = methodSignature.getMethod();
        if (method.isAnnotationPresent(TimeoutBack.class)){
            TimeoutBack annotation = method.getAnnotation(TimeoutBack.class);
            // 超时时间
            Long timeMs = (long) annotation.retryDelay();
            // 重试次数
            int retry = annotation.retry();
            // 降级方法
            String fallback = annotation.fallback();

        }
        return joinPoint.proceed();
    }

}
